/**
 * Beijing Jiaotong University
 * Copyright (c) 1896-2016 All Rights Reserved.
 */
package org.myws.mq.service.impl;

import javax.annotation.Resource;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.myws.dao.mybatis.domain.User;
import org.myws.mq.service.UserMessageSenderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Service;

/**
 * User消息发送者实现类
 * @author HuHui
 * @version $Id: UserMessageSenderServiceImpl.java, v 0.1 2016年5月11日 下午10:07:02 HuHui Exp $
 */
@Service
public class UserMessageSenderServiceImpl implements UserMessageSenderService {

    private static final Logger log = LoggerFactory.getLogger(UserMessageSenderServiceImpl.class);

    @Resource
    private JmsTemplate         jmsTemplage;

    /** 
     * @see org.myws.mq.service.UserMessageSenderService#sendMessage(org.myws.dao.mybatis.domain.User)
     */
    @Override
    public void sendMessage(final User user) {
        log.info("发送消息,参数为user={}", user);
        //发送消息
        jmsTemplage.send(new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                return session.createObjectMessage(user);
            }
        });
        log.info("消息发送完毕");
    }

}
